<template>
    <view class="container">
        <header-bar :config="config"></header-bar>
        <view class="main">
            <view class="cell-group">
                <easy-cell-item
                    :showIcon="false"
                    v-if="false"
                    label="修改密码"
                    value=""
                    @click.native="easyGoTo('/pages/me/changePwd')"></easy-cell-item>
            </view>
            <view class="cell-group" v-if="false">
                <easy-cell-item-switch
                    ref="showProImg"
                    :showIcon="false"
                    label="展示商品图片"
                    :value="isShowProImg"
                    @changeSwitch="changeShowImg"></easy-cell-item-switch>
            </view>
            <view class="cell-group">
                <easy-cell-item
                    :showIcon="false"
                    label="检查版本"
                    :value="getVersion()"
                    @click.native="checkVersion"
                    @longpress.native="longpress">
                </easy-cell-item>
            </view>
            <view class="logout-cell">
                <view class="button-out" @click="logout">退出登录</view>
            </view>
            <view class="tip">
                <text>如需要注销账号，请联系客服人员</text>
            </view>
			<view class="bei-an">闽ICP备15022977号-18A</view>
            <uni-popup ref="popLogout" type="bottom" background-color="#fff" :safe-area="false">
                <view class="bottom-pop">
                    <text class="title">确认退出当前账户?</text>
                    <view class="actions">
                        <button class="btn btn-gray-hollow" @click="closePop">取消</button>
                        <button class="btn btn-danger-hollow" @click="doLogout">退出</button>
                    </view>
                </view>
            </uni-popup>
            <uni-popup ref="popServe" type="bottom" background-color="#fff" :safe-area="false">
                <view class="bottom-pop">
                    <text class="title">切换环境</text>
                    <view class="actions">
                        <button class="btn btn-gray-hollow" @click="selectServer(1)">正式</button>
                        <button class="btn btn-gray-hollow" @click="selectServer(9)">测试</button>
                    </view>
                </view>
            </uni-popup>
        </view>
        <app-version ref="appVersion" :isAutoCheck="false" :appId="getAppId()"></app-version>
    </view>
</template>

<script>
import { mapMutations, mapState } from "vuex"
import storage from "@/uni-sub-base/utils/storage.js"
import easyCellItem from "@/components/easy/easy-cell-item.vue"
import easyCellItemSwitch from "@/components/easy/easy-cell-item-switch.vue"
import easyCellButton from "@/components/easy/easy-cell-button.vue"
import config from "@/config/config.js"

import appVersion from "@/uni-sub-base/module/version/app-version.vue"
export default {
    components: {
        easyCellItem,
        easyCellItemSwitch,
        easyCellButton,
        appVersion,
    },
    data() {
        return {
            config: {
                title: "设置",
                centerSlot: true,
            },
            isShowProImg: true,
        }
    },
    mounted() {
        //获取是否设置不显示商品图片
        let isShowProImg = storage.getCache("isShowProImg")
        if (isShowProImg != null && String(isShowProImg) != "") {
            this.isShowProImg = isShowProImg
        }
    },
    onShow() {},
    methods: {
        ...mapMutations(["SET_SHOW_PRO_IMG", "SET_AUTH"]),
        //退出登录
        logout() {
            this.$refs.popLogout.open()
        },
        //退出登录
        doLogout() {
            this.closePop()
            this.SET_AUTH("")
            storage.removeCache("token")
            storage.removeCache("loginType")
            storage.removeCache("userInfo")
            storage.removeCache("roleArr")
            storage.removeCache("employeeTake")
            storage.removeCache("businessDomain")
            storage.removeCache("jobPosition")
            storage.removeCache("appBaseUrl")
            storage.removeCache("productDisplay")
            storage.removeCache("typeId")
            storage.removeCache("deliveryId")
            storage.removeCache("ImageDomain")
			storage.removeCache("businessID")
            setTimeout(() => {
                this.easyReLaunch("/pages/login/index")
            }, 300)
        },
        //关闭提示弹窗
        closePop() {
            this.$refs.popLogout.close()
        },
        changeShowImg(e) {
            this.SET_SHOW_PRO_IMG(e)
        },
        changePwdFn() {},
        getVersion() {
            //#ifdef APP-PLUS
            let ver = plus.runtime.version
            console.log(ver)
            return ver
            //#endif
            return ""
        },
        longpress() {
            this.$refs.popServe.open()
        },
        selectServer(type) {
            //1正式 0 测试
            storage.setCache("appService", type)
            this.doLogout()
        },
        checkVersion() {
            this.$refs.appVersion.checkVersion()
        },
    },
}
</script>

<style lang="scss">
.main {
    padding: $app-item-padding;
}

.cell-group {
    background: #ffffff;
    border-radius: 8rpx;
}

.logout-cell {
    margin-top: 120rpx;
    .button-out {
        height: 84rpx;
        line-height: 84rpx;
        text-align: center;
        border-radius: 44rpx;
        border: 2rpx solid #000000;
        font-size: 32rpx;
        margin: 0 16rpx;
        color: $color-gray-1;
    }
}

.tip {
    margin-top: 20rpx;
    display: flex;
    justify-content: center;

    text {
        font-size: 24rpx;
        color: $color-gray-2;
    }
}

.bottom-pop {
    .actions {
        margin-top: 40rpx;

        .btn {
            height: 76rpx;
        }
    }
}
.bei-an{
	position:fixed;
	bottom:24rpx;
	text-align: center;
	width: 100%;
	left:0;
}
</style>
